package cc.douquan.com.doutu.adapter;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cc.douquan.com.doutu.MyApplication;
import cc.douquan.com.doutu.R;
import cc.douquan.com.doutu.entity.ClassifyEntity;
import cc.douquan.com.doutu.entity.ItemData;
import cc.douquan.com.doutu.utils.ToastUtils;
import cc.douquan.com.doutu.utils.UiHelper;
import cc.douquan.com.doutu.view.DividerGridItemDecoration;

import static cc.douquan.com.doutu.R.id.recyclerview;

/**
 * Created by qef on 2016/9/11.
 * 瀑布流适配器11
 */
public class FindPictureAdapter extends BaseSectionQuickAdapter<ItemData> {
    private GridLayoutManager mGridViewLayoutManager;//recycleview视图样式管理器
    private FenleiAdapter mAdapter;

    public FindPictureAdapter(int layoutResId, int sectionHeadResId, List<ItemData> data) {
        super(layoutResId, sectionHeadResId, data);
    }

    @Override
    protected void convertHead(BaseViewHolder baseViewHolder, ItemData itemData) {
        baseViewHolder.setText(R.id.tv_head_name, itemData.header);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, ItemData itemData) {
        ClassifyEntity.DataEntity t = itemData.t;
        final List<ClassifyEntity.DataEntity.TagListEntity> tagList = t.getTagList();
        RecyclerView rcItem = baseViewHolder.getView(R.id.rc_item);
        initRecyclerView(rcItem);
        mAdapter = new FenleiAdapter(R.layout.item_feilei_pic, tagList);
        mAdapter.setOnRecyclerViewItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int i) {
                UiHelper.goClassityActivity(mContext, tagList.get(i).getId());
            }
        });
        mAdapter.setOnRecyclerViewItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int i) {
//                ToastUtils.showShort(tagList.get(i).getGifPath());
                Bundle bundle = new Bundle();
                bundle.putInt("type_id", tagList.get(i).getId());
                bundle.putString("type_title", tagList.get(i).getName());
                UiHelper.goTypeActivity(mContext, bundle);
            }
        });
        rcItem.setAdapter(mAdapter);
    }

    void initRecyclerView(RecyclerView rcItem) {
        mGridViewLayoutManager = new GridLayoutManager(MyApplication.getContext(), 4);
//        rcItem.addItemDecoration(new DividerGridItemDecoration(MyApplication.getContext()));
        rcItem.setLayoutManager(mGridViewLayoutManager);
    }
}
